package wibrst.utils{
	/**
	 * ...
	 * @author wibrst@qq.com
	 */
	public class ArrayUtil{
		
		static public function shuffle(aOrig:Array):void {
			for ( var i:Number = aOrig.length - 1; i > -1; --i) {
				var r:Number = Math.floor( aOrig.length * Math.random() );		/// produce random idx
				var tmp:Object = aOrig[i]; aOrig[i] = aOrig[r]; aOrig[r] = tmp;		/// swap element between thru idx and randm idx
			}
		}
		
		static public function getRdmElem( aSrc:Array, nStart:Number = 0, nEnd:Number = -1 ):* {
			if ( nEnd == -1 ) nEnd = aSrc.length;
			
			var nLenValid:Number = nEnd - nStart;
			return aSrc[ getRdmIdx( nLenValid, nStart ) ];
		}
		
		static public function getRdmIdx( nLen:Number, nBase:Number = 0 ):Number {
			return nBase + int( Math.random() * nLen );
		}
		
		// 取得序列数组
		static public function getSeriesNumArr( iLen:Number, iStart:Number = 0 ):Array {
			//trace( "[CommUtils] getSeriesNumArr", arguments );
			if ( iLen <= 0 ) {
				return [];
			}
			
			var aProd:Array = new Array;
			for ( var i:Number = iStart + iLen - 1; i >= iStart; --i ) {
				aProd.unshift( i );
			}
			return aProd;
		}
		
	}

}